<div data-hook="admin_shipping_method_form_fields" class="row">
  <div data-hook="admin_shipping_method_form_name_field" class="col-xs-5">
    <%= f.field_container :name do %>
      <%= f.label :name %><br />
      <%= f.text_field :name, :class => 'fullwidth' %>
      <%= error_message_on :shipping_method, :name %>
    <% end %>
  </div>

  <div data-hook="admin_shipping_method_form_display_field" class="col-xs-5">
    <%= f.field_container :display_on do %>
      <%= f.label :display_on %><br />
      <%= select(:shipping_method, :display_on, Spree::ShippingMethod::DISPLAY.collect { |display| [Spree.t(display), display == :both ? nil : display.to_s] }, {}, {:class => 'select2 fullwidth'}) %>
      <%= error_message_on :shipping_method, :display_on %>
    <% end %>
  </div>

  <div data-hook="admin_shipping_method_form_internal_name_field" class="col-xs-5">
    <%= f.field_container :admin_name do %>
      <%= f.label :admin_name %><br />
      <%= f.text_field :admin_name, :class => 'fullwidth', :label => false  %>
      <%= error_message_on :shipping_method, :admin_name %>
    <% end %>
  </div>

  <div data-hook="admin_shipping_method_form_code" class="col-xs-5">
    <%= f.field_container :code do %>
      <%= f.label :code %><br />
      <%= f.text_field :code, :class => 'fullwidth', :label => false  %>
      <%= error_message_on :shipping_method, :code %>
    <% end %>
  </div>

  <div class="col-xs-5">
    <%= f.field_container :carrier do %>
      <%= f.label :carrier %><br />
      <%= f.text_field :carrier, :class => 'fullwidth', :label => false  %>
      <%= error_message_on :shipping_method, :carrier %>
    <% end %>
  </div>

  <div class="col-xs-5">
    <%= f.field_container :service_level do %>
      <%= f.label :service_level %><br />
      <%= f.text_field :service_level, :class => 'fullwidth', :label => false  %>
      <%= error_message_on :shipping_method, :service_level %>
    <% end %>
  </div>

  <div data-hook="admin_shipping_method_form_tracking_url_field" class="col-xs-10">
    <%= f.field_container :tracking_url do %>
      <%= f.label :tracking_url %><br />
      <%= f.text_field :tracking_url, :class => 'fullwidth', :placeholder => Spree.t(:tracking_url_placeholder) %>
      <%= error_message_on :shipping_method, :tracking_url %>
    <% end %>
  </div>
</div>

<div class="row">
  <div class="col-xs-5">
    <div data-hook="admin_shipping_method_form_availability_fields" class="col-xs-5">
      <fieldset class="categories no-border-bottom">
        <legend align="center"><%= plural_resource_name(Spree::ShippingCategory) %></legend>
        <%= f.field_container :categories do %>
          <% Spree::ShippingCategory.all.each do |category| %>
            <%= label_tag do %>
              <%= check_box_tag('shipping_method[shipping_categories][]', category.id, @shipping_method.shipping_categories.include?(category)) %>
              <%= category.name %><br>
            <% end %>
          <% end %>
          <%= error_message_on :shipping_method, :shipping_category_id %>
        <% end %>
      </fieldset>
    </div>

    <div class="col-xs-5">
      <fieldset class="no-border-bottom">
        <legend align="center"><%= plural_resource_name(Spree::Zone) %></legend>
        <%= f.field_container :zones do %>
          <% shipping_method_zones = @shipping_method.zones.to_a %>
          <% Spree::Zone.all.each do |zone| %>
            <%= label_tag do %>
              <%= check_box_tag('shipping_method[zones][]', zone.id, shipping_method_zones.include?(zone)) %>
              <%= zone.name %>
            <% end %>
            <br>
          <% end %>
          <%= error_message_on :shipping_method, :zone_id %>
        <% end %>
      </fieldset>
    </div>
  </div>
  <div class="col-xs-5">
    <div data-hook="admin_shipping_method_form_calculator_fields" class="col-xs-5">
      <%= render :partial => 'spree/admin/shared/calculator_fields', :locals => { :f => f } %>
    </div>
    <div class="col-xs-5">
      <fieldset class="tax_categories no-border-bottom">
        <legend align="center"><%= Spree::TaxCategory.model_name.human %></legend>
          <%= f.field_container :tax_categories do %>
            <%= f.select :tax_category_id, @tax_categories.map { |tc| [tc.name, tc.id] }, {include_blank: true}, class: "select2 fullwidth" %>
            <%= error_message_on :shipping_method, :tax_category_id %>
          <% end %>
      </fieldset>
    </div>
  </div>
</div>
